﻿using Lsk.Business.DTO;
using Lsk.Data;
using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lsk.Business
{
    public class Auction
    {
        private Lsk.Data.lskEntities _entity;

        public Auction()
        {
            _entity = new lskEntities();
        }

        public IEnumerable<GetAuction_Result> GetAuction()
        {
            ObjectResult<GetAuction_Result> auction = _entity.GetAuction(0);
            return auction.AsEnumerable<GetAuction_Result>();
        }

        public AuctionMessage GetAuction(string guid)
        {
            AuctionMessage response = new AuctionMessage();
            //GetAuction_Result data = (from a in _entity.GetAuction where a.LelongId == new Guid(guid) select a).FirstOrDefault();
            GetAuction_Result data = (from a in _entity.GetAuction(0).AsEnumerable() where a.LelongId == new Guid(guid) select a).FirstOrDefault();
            response.Auction = data;
            IEnumerable<GetPictureByID_Result> picture;
            int pictureCount = (from a in _entity.AW_Picture where a.PropertyId == new Guid(guid) select a).Count();
            if (pictureCount > 0)
            {
                picture = _entity.GetPictureByID(guid).ToList();
                response.pictureList = picture;
            }
            //response.pictureList = _entity.GetPictureByID(guid);
            return response;
        }
    }
}
